package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.BrandAndNewDTO;
import cn.tedu.csmall.product.pojo.vo.BrandListItemVO;
import cn.tedu.csmall.product.pojo.vo.BrandStandardVO;
import cn.tedu.csmall.product.service.IBrandService;
import cn.tedu.csmall.product.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "01.品牌管理模块")
@RestController
@Slf4j
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    IBrandService service;
    public BrandController() {
        log.info("创建配置器:BrandController");
    }
    @ApiOperation("添加品牌数据")
    @PostMapping("and-new")
    public JsonResult andNew(@Validated BrandAndNewDTO brandAndNewDTO){
        log.debug("开始处理业务{}",brandAndNewDTO);
        service.andNew(brandAndNewDTO);
        return JsonResult.ok();
    }
    @ApiOperation("删除品牌数据")
    @PostMapping("/{id:[0-9]+}/delete")
    public String delete(@PathVariable Long id) {
        service.delete(id);
        return "删除完成!";
    }
    @ApiOperation("查询品牌数据")
    @GetMapping("/getbrand")
    public JsonResult<List<BrandListItemVO>> getBrandList(){
      log.debug("开始查询数据");
        List<BrandListItemVO> brandListItemVOS = service.listBrand();
        return JsonResult.ok(brandListItemVOS);
    }
    @ApiOperation("根据id查询品牌数据")
    @GetMapping("/{id:[1-9]+}/get")
    public JsonResult<BrandStandardVO> getBrand(@PathVariable Long id){
        log.debug("开始查询数据");
        BrandStandardVO serviceBrand = service.getBrand(id);
        return JsonResult.ok(serviceBrand);
    }
}
